import React, { Component } from "react";
import { connect } from "react-redux";

import { changeAction } from "./store/actionCreator";

const mapStateToProps = (state) => {
  // console.log(state);
  return {
    count: state.get("count"),
  };
};
const mapDispatchToProps = (dispatch) => {
  return {
    change(num) {
      dispatch(changeAction(num));
    },
  };
};

@connect(mapStateToProps, mapDispatchToProps)
class Counter extends Component {
  state = {};
  render() {
    return (
      <>
        <button onClick={() => this.props.change(-1)}>-</button>
        <span>{this.props.count}</span>
        <button onClick={() => this.props.change(1)}>+</button>
      </>
    );
  }
}

export default Counter;
